<?php
//@author baimengzhao to SeminaOrder add start 2012/4/6
	class SeminaOrder extends AppModel{
		var $name="SeminaOrder";
		var $useTable="semina_order_mst";
		var $primaryKey = 'id';
	
		var $belongsTo = array(
						'Semina'=>array(
						'className'=>'Semina', 'conditions'=>'', 'order'=>'',
						'foreignKey'=>'semina_id'
				)
			);
		//@author baimengzhao to dodelete add start 2012/4/6
		function dodelete($semina_id) {
			$sql = "update semina_order_mst SET member_deleted = now() WHERE id=$semina_id";
			$this->query($sql);
		}
		
		//@author baimengzhao to getOrderSemina add start 2012/4/6
		function getOrderSemina($id,$limit = null, $page = 1)
		{
			$offset = null;
			
			if ($page > 1 && $limit != null) {
				$offset = 'offset '.($page - 1) * $limit;
			}
			$sql = "select * from (
			select om.job_id,om.id,om.created,jm.title,jm.small_title,ci.company_name,ci.company_alias,jm.company_id,jm.company_name_flg,jm.company_name_other,jm.location_title,1 as flg
			"
			//lfx added 2013-09-12 start
			.",jm.cn_asia"
			//lfx added 2013-09-12 end
			." from order_mst om
			join job_mst jm on jm.id = om.job_id  join company_info ci on ci.id=jm.company_id 
			where om.member_id =".$id." and om.deleted is null
			union
			select 88,som.id,som.created,sm.title,som.order_content,'','',88,88,'','',2 as flg
			"
			//lfx added 2013-09-12 start
			.",'-' as cn_asia"
			//lfx added 2013-09-12 end
			." from semina_order_mst som
			join semina_mst sm on sm.id = som.semina_id
			where som.member_id =".$id." and som.member_deleted is null and som.deleted is null  ) as order_info
			order by created desc  limit ".$limit.' '.$offset;
			$data=$this->query($sql);
			foreach($data as $key=>$value){
				$info['data'][$key]=$value[0];
				if($value[0]['flg']==1)
				{
					$info['data'][$key]['infourl'] = '/order/detail/'.$info['data'][$key]['id'];
					$info['data'][$key]['delurl'] = '/order/delete_info/'.$info['data'][$key]['id'];
				}else{
					$info['data'][$key]['infourl'] = '/order/detail_semina_order/'.$info['data'][$key]['id'];
					$info['data'][$key]['delurl'] = '/order/delete_semina_order/'.$info['data'][$key]['id'];
				}
				
			}
			$count_sql = "select * from (
			select om.job_id,om.id,om.created,jm.title,jm.small_title,ci.company_name,ci.company_alias,jm.company_id,jm.company_name_flg,jm.company_name_other,jm.location_title,1 as flg from order_mst om
			join job_mst jm on jm.id = om.job_id  join company_info ci on ci.id=jm.company_id 
			where om.member_id =".$id." and om.deleted is null
			union
			select 88,som.id,som.created,sm.title,som.order_content,'','',88,88,'','',2 as flg from semina_order_mst som
			join semina_mst sm on sm.id = som.semina_id
			where som.member_id =".$id." and som.member_deleted is null and som.deleted is null  ) as order_info
			order by created desc ";
			$info['count'] = count($this->query($count_sql));
			
			return $info;
		}
		
		//@author baimengzhao to delete_semina_order add start 2012/4/7
		function getSeminaOrder($order)
		{
			$order['login_url']='/order';
			$order['backurl']='/order';
			$order['delurl']='/order/delete_semina_order/'.$order['SeminaOrder']['id'];
			return $order;
		}
		
	}
?>